package com.java.control.impl;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;

import com.java.control.AbstractAdminCommandController;
import com.java.control.search.SearchStat;
import com.java.control.search.SupplierQuotationSearchCond;
import com.java.entity.Product;
import com.java.entity.SupplierQuotation;
import com.java.service.ProductService;
import com.java.service.SupplierQuotationService;

/**
 * 产品右边供应商报价信息控制器
 * @author wqf
 * @version  Nov 14, 2011 2:38:40 PM
 */
public class ProductRightController extends AbstractAdminCommandController {
	
	public ProductRightController(){
		this.setCommandClass(SupplierQuotationSearchCond.class);
	}	
	
	private String successView;
	public void setSuccessView(String successView) {
		this.successView = successView;
	}
	
	protected ModelAndView executeRequest(HttpServletRequest request,HttpServletResponse response,Object command)
	throws Exception{
		ModelAndView mav=new ModelAndView(this.successView);
		String pid=request.getParameter("pid");
		SupplierQuotationSearchCond searchCond = (SupplierQuotationSearchCond)command;
		SearchStat searchStat = new SearchStat();
		List<SupplierQuotation> List = null;
		Product product = null;
		if(null!=pid){
			product = this.productService.getProductById(Long.parseLong(pid));
			if(null!=product){				
				searchCond.setPageSize(10L);
				searchCond.setProductId(product.getId());
				searchStat = this.supplierQuotationService.getSearchStat(SupplierQuotation.class, searchCond);
				List = this.supplierQuotationService.search(SupplierQuotation.class,searchCond,"id desc");						
			}
		}
		mav.addObject("product", product);
		mav.addObject("searchStat", searchStat);
		mav.addObject("searchCond", searchCond);
		mav.addObject("supplierQuotationList", List);
		
		return mav;
	
	}
	
	private SupplierQuotationService supplierQuotationService;
	private ProductService productService;
	
	public String getSuccessView() {
		return successView;
	}

	public SupplierQuotationService getSupplierQuotationService() {
		return supplierQuotationService;
	}

	public ProductService getProductService() {
		return productService;
	}

	public void setProductService(ProductService productService) {
		this.productService = productService;
	}

	public void setSupplierQuotationService(
			SupplierQuotationService supplierQuotationService) {
		this.supplierQuotationService = supplierQuotationService;
	}

}
